﻿using System;

namespace ThresholdAssistant.Enums.Extensions
{
    /// <summary>
    /// 底层协议类型转换
    /// </summary>
    public static class ProtocolTypeExtensions
    {
        /// <summary>
        /// 转换机器人推送指令
        /// </summary>
        /// <param name="protocolType">协议类型</param>
        /// <returns></returns>
        public static RobotPushTargetType ToPushTargetType(this RobotProtocolType protocolType)
        {
            switch (protocolType)
            {
                case RobotProtocolType.iPad:
                case RobotProtocolType.iPhone:
                    return RobotPushTargetType.IOS;
                case RobotProtocolType.android_box:
                case RobotProtocolType.AndroidSimulator:
                    return RobotPushTargetType.Emulator;
                case RobotProtocolType.android_phone:
                    return RobotPushTargetType.android_phone;
                case RobotProtocolType.Android:
                case RobotProtocolType.android_pad_protocol:
                    return RobotPushTargetType.Android;
                case RobotProtocolType.windows:
                case RobotProtocolType.windows_guard:
                case RobotProtocolType.windows_pdd:
                case RobotProtocolType.windows_local:
                    return RobotPushTargetType.Windows;
                case RobotProtocolType.windows_protocol:
                    return RobotPushTargetType.windows_protocol;
                case RobotProtocolType.az_protocol:
                    return RobotPushTargetType.az_protocol;
                case RobotProtocolType.mac_protocol:
                    return RobotPushTargetType.mac_protocol;
                case RobotProtocolType.cloud_protocol:
                    return RobotPushTargetType.cloud_protocol;
            }
            throw new ArgumentException("PushTargetType参数protocolType异常");
        }

        /// <summary>
        /// 转换机器人推送指令
        /// </summary>
        /// <param name="deviceUserRobotType">设备心跳表机器人类型</param>
        /// <returns></returns>
        public static RobotPushTargetType ToPushTargetType(this DeviceUserRobotTypeEnum deviceUserRobotType)
        {
            switch (deviceUserRobotType)
            {
                case DeviceUserRobotTypeEnum.iPad:
                case DeviceUserRobotTypeEnum.iPhone:
                    return RobotPushTargetType.IOS;
                case DeviceUserRobotTypeEnum.androidSimulator:
                    return RobotPushTargetType.Emulator;
                case DeviceUserRobotTypeEnum.android:
                case DeviceUserRobotTypeEnum.android_pad_protocol:
                    return RobotPushTargetType.Android;
                case DeviceUserRobotTypeEnum.windows:
                    return RobotPushTargetType.Windows;
                case DeviceUserRobotTypeEnum.android_phone:
                    return RobotPushTargetType.android_phone;
                case DeviceUserRobotTypeEnum.windows_protocol:
                    return RobotPushTargetType.windows_protocol;
                case DeviceUserRobotTypeEnum.az_protocol:
                    return RobotPushTargetType.az_protocol;
                case DeviceUserRobotTypeEnum.mac_protocol:
                    return RobotPushTargetType.mac_protocol;
                case DeviceUserRobotTypeEnum.cloud_protocol:
                    return RobotPushTargetType.cloud_protocol;
            }
            throw new ArgumentException("PushTargetType参数deviceUserRobotType异常");
        }

        /// <summary>
        /// 转换机器人推送指令
        /// </summary>
        /// <param name="deviceUserRobotType"></param>
        /// <returns></returns>
        public static RobotPushTargetType ToPushTargetType(this int deviceUserRobotType)
        {
            switch (deviceUserRobotType)
            {
                case 0:
                case 30:
                    return RobotPushTargetType.IOS;
                case 31:
                    return RobotPushTargetType.Emulator;
                case 32:
                case 38:
                    return RobotPushTargetType.Android;
                case 36:
                    return RobotPushTargetType.az_protocol;
                case 33:
                    return RobotPushTargetType.Windows;
                case 34:
                    return RobotPushTargetType.android_phone;
                case 35:
                    return RobotPushTargetType.windows_protocol;
                case 37:
                    return RobotPushTargetType.mac_protocol;
                case 39:
                    return RobotPushTargetType.cloud_protocol;
            }
            throw new ArgumentException("PushTargetType参数deviceUserRobotType异常");
        }

        /// <summary>
        /// 转换机器人类型
        /// </summary>
        /// <param name="protocolType">协议类型</param>
        /// <returns></returns>
        public static OLDRobotTypeEnum ToRobotType(this RobotProtocolType protocolType)
        {
            switch (protocolType)
            {
                case RobotProtocolType.iPad:
                    return OLDRobotTypeEnum.iPhone;
                case RobotProtocolType.iPhone:
                    return OLDRobotTypeEnum.iPhone;
                case RobotProtocolType.android_box:
                    return OLDRobotTypeEnum.android_box;
                case RobotProtocolType.AndroidSimulator:
                    return OLDRobotTypeEnum.AndroidSimulator;
                case RobotProtocolType.Android:
                    return OLDRobotTypeEnum.Android;
                case RobotProtocolType.az_protocol:
                    return OLDRobotTypeEnum.az_protocol;
                case RobotProtocolType.windows_protocol:
                    return OLDRobotTypeEnum.windows_protocol;
                case RobotProtocolType.mac_protocol:
                    return OLDRobotTypeEnum.mac_protocol;
                case RobotProtocolType.windows:
                case RobotProtocolType.windows_local:
                    return OLDRobotTypeEnum.Windows;
                case RobotProtocolType.android_phone:
                    return OLDRobotTypeEnum.android_phone;
                case RobotProtocolType.android_pad_protocol:
                    return OLDRobotTypeEnum.android_pad_protocol;
                default:
                    return OLDRobotTypeEnum.Default;
            }
            throw new ArgumentException("RobotTypeEnum参数protocolType异常");
        }

        /// <summary>
        /// 转换设备心跳的机器人类型
        /// </summary>
        /// <param name="protocolType">协议类型</param>
        /// <returns></returns>
        public static DeviceUserRobotTypeEnum ToDeviceUserRobotType(this RobotProtocolType protocolType)
        {
            switch (protocolType)
            {
                case RobotProtocolType.iPad:
                    return DeviceUserRobotTypeEnum.iPad;
                case RobotProtocolType.iPhone:
                    return DeviceUserRobotTypeEnum.iPhone;
                case RobotProtocolType.android_box:
                case RobotProtocolType.AndroidSimulator:
                    return DeviceUserRobotTypeEnum.androidSimulator;
                case RobotProtocolType.Android:
                    return DeviceUserRobotTypeEnum.android;
                case RobotProtocolType.az_protocol:
                    return DeviceUserRobotTypeEnum.az_protocol;
                case RobotProtocolType.windows_protocol:
                    return DeviceUserRobotTypeEnum.windows_protocol;
                case RobotProtocolType.mac_protocol:
                    return DeviceUserRobotTypeEnum.mac_protocol;
                case RobotProtocolType.windows:
                case RobotProtocolType.windows_local:
                    return DeviceUserRobotTypeEnum.windows;
                case RobotProtocolType.android_phone:
                    return DeviceUserRobotTypeEnum.android_phone;
                case RobotProtocolType.android_pad_protocol:
                    return DeviceUserRobotTypeEnum.android_pad_protocol;
                case RobotProtocolType.cloud_protocol:
                    return DeviceUserRobotTypeEnum.cloud_protocol;
            }
            throw new ArgumentException("ToDeviceUserRobotType参数protocolType异常");
        }


        /// <summary>
        /// 转换企微指令推送类型
        /// </summary>
        /// <param name="protocolType"></param>
        /// <returns></returns>
        public static string ToWorkRobotType(this RobotProtocolType protocolType)
        {
            switch (protocolType)
            {
                case RobotProtocolType.iPad:
                    return "ipad";
                case RobotProtocolType.iPhone:
                    return "iphone";
                case RobotProtocolType.AndroidSimulator:
                    return "android_emulator";
                case RobotProtocolType.Android:
                    return "android";
                case RobotProtocolType.android_box:
                    return "android_box";
                case RobotProtocolType.windows:
                    return "windows";
                case RobotProtocolType.cloud_protocol:
                    return "android_cloud";
                case RobotProtocolType.windows_local:
                    return "windows_local";
                case RobotProtocolType.windows_guard:
                    return "windows_guard";
            }
            throw new ArgumentException("ToWorkRobotType参数protocolType异常");
        }
    }
}